import random
import pickle
import numpy as np


def mazeBuild3D():  # 调用本身存储的地图
    with open('obstacle.pkl', 'rb') as f:
        obstacledata = pickle.load(f)
    print(obstacledata)
    return obstacledata


def ObstacleCreate(obstacleNum, length, width, height, startPoint, endPoint):  # 三维障碍生成算法
    obstacle = []
    fail = 0
    for i in range(obstacleNum):
        x = random.randint(0, length - 1) - 0.5
        y = random.randint(0, width - 1) - 0.5
        h = int(abs(random.gauss(int(height * 0.5) - 1, 5)))
        location = (x, y, h)
        if x == startPoint[0] - 0.5 and y == startPoint[1] - 0.5:
            fail = 1
        if x == endPoint[0] - 0.5 and y == endPoint[1] - 0.5:
            fail = 1
        if fail == 0:
            obstacle.append(location)

    return obstacle
